<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const isLoggedIn = ref(false)
const username = ref('')
const userAvatar = ref('https://api.dicebear.com/7.x/avataaars/svg?seed=user') // 使用dicebear作为头像源
const searchQuery = ref('')
const showUserMenu = ref(false)
const showCategoryMenu = ref(false)
const showMobileMenu = ref(false)
const cartCount = ref(5) // 模拟购物车商品数量

// 检查用户登录状态
const checkLoginStatus = () => {
  isLoggedIn.value = localStorage.getItem('isLoggedIn') === 'true'
  username.value = localStorage.getItem('username') || ''
}

// 退出登录函数
const handleLogout = () => {
  localStorage.removeItem('isLoggedIn')
  localStorage.removeItem('username')
  isLoggedIn.value = false
  username.value = ''
  showUserMenu.value = false
  router.push('/login')
}

// 跳转到登录页
const goToLogin = () => {
  router.push('/login')
}

// 切换用户菜单显示状态
const toggleUserMenu = () => {
  showUserMenu.value = !showUserMenu.value;
}

// 切换分类菜单显示状态
const toggleCategoryMenu = () => {
  showCategoryMenu.value = !showCategoryMenu.value;
}

// 切换移动端菜单显示状态
const toggleMobileMenu = () => {
  showMobileMenu.value = !showMobileMenu.value;
}

// 执行搜索
const performSearch = () => {
  if (searchQuery.value.trim()) {
    console.log('搜索:', searchQuery.value);
    // 这里可以添加搜索逻辑
  }
}

// 监听搜索框回车事件
const handleSearchKeydown = (event) => {
  if (event.key === 'Enter') {
    performSearch();
  }
}

// 组件挂载时检查登录状态
onMounted(() => {
  checkLoginStatus()
  
  // 点击页面其他地方关闭下拉菜单
  const handleClickOutside = (event) => {
    if (!event.target.closest('.user-menu') && !event.target.closest('.category-dropdown') && !event.target.closest('.mobile-menu-toggle')) {
      showUserMenu.value = false;
      showCategoryMenu.value = false;
    }
  };
  
  document.addEventListener('click', handleClickOutside);
  
  // 清理事件监听器
  return () => {
    document.removeEventListener('click', handleClickOutside);
  };
})
</script>

<template>
  <header class="jd-header">
    <!-- 顶部导航栏 -->
    <div class="top-bar">
      <div class="container">
        <div class="top-links">
          <a href="#" class="top-link">京东首页</a>
          <span class="separator">|</span>
          <a href="#" class="top-link">京东超市</a>
          <span class="separator">|</span>
          <a href="#" class="top-link">京东电器</a>
          <span class="separator">|</span>
          <a href="#" class="top-link">京东生鲜</a>
          <span class="separator">|</span>
          <a href="#" class="top-link">全球购</a>
          <span class="separator">|</span>
          <a href="#" class="top-link">客户服务</a>
          <span class="separator">|</span>
          <a href="#" class="top-link">PLUS会员</a>
        </div>
      </div>
    </div>
    
    <!-- 主导航区 -->
    <div class="header-main">
      <div class="container">
        <div class="header-content">
          <!-- Logo区域 -->
          <div class="logo-section">
            <a href="/" class="logo">
              <img src="https://via.placeholder.com/190x60?text=京东商城" alt="京东商城" class="jd-logo">
            </a>
          </div>
          
          <!-- 搜索框 -->
          <div class="search-section">
            <div class="search-box">
              <input type="text" placeholder="家用电器、手机、电脑、服装、鞋包..." class="search-input" v-model="searchQuery" @keydown.enter="handleSearchKeydown">
              <button class="search-button" @click="performSearch">搜索</button>
            </div>
          </div>
          
          <!-- 用户操作区 -->
          <div class="user-actions">
            <!-- 移动端菜单按钮 -->
            <button class="mobile-menu-toggle hidden-desktop" @click="toggleMobileMenu">
              <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M3 12H21M3 6H21M3 18H21" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
              </svg>
            </button>
            
            <!-- 分类菜单 -->
            <div class="category-dropdown hidden-mobile">
              <button class="category-button" @click="toggleCategoryMenu">
                <svg width="16" height="16" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                  <path d="M4 6H20M4 12H20M4 18H11" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                </svg>
                <span>全部分类</span>
              </button>
              <div class="category-menu" :class="{ 'show': showCategoryMenu }">
                <div class="category-items">
                  <a href="#" class="category-item">
                    <span class="category-name">手机</span>
                    <span class="category-more">></span>
                  </a>
                  <a href="#" class="category-item">
                    <span class="category-name">电脑</span>
                    <span class="category-more">></span>
                  </a>
                  <a href="#" class="category-item">
                    <span class="category-name">家电</span>
                    <span class="category-more">></span>
                  </a>
                  <a href="#" class="category-item">
                    <span class="category-name">数码</span>
                    <span class="category-more">></span>
                  </a>
                  <a href="#" class="category-item">
                    <span class="category-name">家居</span>
                    <span class="category-more">></span>
                  </a>
                  <a href="#" class="category-item">
                    <span class="category-name">美妆</span>
                    <span class="category-more">></span>
                  </a>
                  <a href="#" class="category-item">
                    <span class="category-name">服饰</span>
                    <span class="category-more">></span>
                  </a>
                  <a href="#" class="category-item">
                    <span class="category-name">鞋包</span>
                    <span class="category-more">></span>
                  </a>
                  <a href="#" class="category-item">
                    <span class="category-name">食品</span>
                    <span class="category-more">></span>
                  </a>
                  <a href="#" class="category-item">
                    <span class="category-name">母婴</span>
                    <span class="category-more">></span>
                  </a>
                </div>
              </div>
            </div>
            
            <!-- 导航链接 -->
            <div class="nav-links hidden-mobile">
              <a href="#" class="nav-link">秒杀</a>
              <a href="#" class="nav-link">优惠券</a>
              <a href="#" class="nav-link">PLUS会员</a>
              <a href="#" class="nav-link">京东超市</a>
              <a href="#" class="nav-link">京东电器</a>
            </div>
            
            <!-- 登录/用户信息 -->
            <div v-if="!isLoggedIn" class="login-section">
              <button @click="goToLogin" class="login-button">
                <span>你好，请登录</span>
              </button>
            </div>
            
            <!-- 已登录用户菜单 -->
            <div v-else class="user-menu">
              <button class="user-menu-button" @click="toggleUserMenu">
                <img :src="userAvatar" alt="用户头像" class="user-avatar" style="width: 24px; height: 24px; border-radius: 50%; margin-right: 8px;">
                <span class="user-name">{{ username }}</span>
                <svg width="12" height="12" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                  <path d="M6 9L12 15L18 9" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                </svg>
              </button>
              
              <!-- 用户下拉菜单 -->
              <div class="user-dropdown" :class="{ 'show': showUserMenu }">
                <router-link to="/profile" class="dropdown-item" @click="showUserMenu = false">
                  个人中心
                </router-link>
                <router-link to="/favorites" class="dropdown-item" @click="showUserMenu = false">
                  我的收藏
                </router-link>
                <router-link to="/history" class="dropdown-item" @click="showUserMenu = false">
                  浏览历史
                </router-link>
                <a href="#" class="dropdown-item">我的订单</a>
                <a href="#" class="dropdown-item">客户服务</a>
                <div class="dropdown-divider"></div>
                <button class="dropdown-item logout" @click="handleLogout">
                  退出登录
                </button>
              </div>
            </div>
            
            <!-- 购物车 -->
            <a href="#" class="cart-button">
              <svg width="20" height="20" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M4 6H20M4 12H20M4 18H14" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
              </svg>
              <span>购物车</span>
              <span class="cart-count">{{ cartCount }}</span>
            </a>
          </div>
        </div>
      </div>
    </div>
    
    <!-- 移动端菜单 -->
    <div class="mobile-menu" :class="{ 'show': showMobileMenu }">
      <nav class="mobile-nav">
        <div class="mobile-category">
          <h3>商品分类</h3>
          <ul class="mobile-category-list">
            <li><a href="#" class="mobile-category-link">手机</a></li>
            <li><a href="#" class="mobile-category-link">电脑</a></li>
            <li><a href="#" class="mobile-category-link">家电</a></li>
            <li><a href="#" class="mobile-category-link">数码</a></li>
            <li><a href="#" class="mobile-category-link">家居</a></li>
            <li><a href="#" class="mobile-category-link">美妆</a></li>
            <li><a href="#" class="mobile-category-link">服饰</a></li>
          </ul>
        </div>
        <div class="mobile-user">
          <h3>我的京东</h3>
          <ul class="mobile-user-list">
            <li><a href="#" class="mobile-user-link">个人中心</a></li>
            <li><a href="#" class="mobile-user-link">我的订单</a></li>
            <li><a href="#" class="mobile-user-link">我的收藏</a></li>
            <li><a href="#" class="mobile-user-link">浏览历史</a></li>
            <li><a href="#" class="mobile-user-link">客户服务</a></li>
          </ul>
        </div>
      </nav>
    </div>
  </header>
</template>

<style scoped>
/* 京东风格颜色变量 */
:root {
  --jd-red: #e1251b;
  --jd-red-light: #f08480;
  --jd-blue: #0052d9;
  --jd-orange: #f56600;
  --jd-yellow: #ffb31a;
  --jd-green: #00a854;
  --jd-gray: #8c8c8c;
  --jd-gray-light: #e7e7e7;
  --jd-white: #ffffff;
  --jd-black: #333333;
  --jd-shadow-sm: 0 2px 4px rgba(0,0,0,0.1);
  --jd-shadow-md: 0 4px 8px rgba(0,0,0,0.1);
  --jd-shadow-lg: 0 8px 16px rgba(0,0,0,0.15);
}

/* 顶部导航栏 */
.top-bar {
  background-color: var(--jd-red);
  color: white;
  font-size: 12px;
  height: 30px;
  display: flex;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.top-bar .container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.top-links {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
}

.top-link {
  color: white;
  text-decoration: none;
  transition: all 0.3s ease;
  position: relative;
}

.top-link:hover {
  color: #fff2cc;
  transform: translateY(-1px);
}

.separator {
  color: rgba(255, 255, 255, 0.6);
}

/* 主导航区 */
.header-main {
  background-color: var(--jd-white);
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  position: sticky;
  top: 0;
  z-index: 100;
  transition: all 0.3s ease;
}

.header-main:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.header-main .container {
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.header-content {
  display: flex;
  align-items: center;
  padding: 15px 24px;
  gap: 20px;
}

/* Logo区域 */
.logo-section {
  flex-shrink: 0;
  width: 190px;
}

.logo {
  display: flex;
  align-items: center;
  transition: transform 0.3s ease;
}

.logo:hover {
  transform: scale(1.03);
}

.jd-logo {
  width: 190px;
  height: 60px;
  object-fit: contain;
}

/* 搜索框 */
.search-section {
  flex: 1;
  max-width: 550px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  background-color: #f5f5f5;
  border-radius: 25px;
  overflow: hidden;
  transition: all 0.3s ease;
}

.search-box:focus-within {
  box-shadow: 0 2px 8px rgba(225, 37, 27, 0.2);
  transform: translateY(-1px);
}

.search-input {
  border: none;
  background: var(--jd-white);
  padding: 12px 18px;
  font-size: 14px;
  width: 100%;
  color: var(--jd-black);
  border: 2px solid #f5f5f5;
  border-right: none;
  outline: none;
  border-top-left-radius: 25px;
  border-bottom-left-radius: 25px;
}

.search-input:focus {
  border-color: var(--jd-red);
}

.search-input::placeholder {
  color: #9c9c9c;
}

.search-button {
  background: linear-gradient(135deg, var(--jd-red), #ff4d4f);
  border: none;
  color: var(--jd-white);
  cursor: pointer;
  padding: 12px 24px;
  font-size: 14px;
  font-weight: bold;
  transition: all 0.3s ease;
  border-top-right-radius: 25px;
  border-bottom-right-radius: 25px;
  position: relative;
  overflow: hidden;
}

.search-button:before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: all 0.5s;
}

.search-button:hover:before {
  left: 100%;
}

.search-button:hover {
  background: linear-gradient(135deg, #c81623, #ff7875);
  transform: translateY(-1px);
}

/* 用户操作区 */
.user-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

/* 移动端菜单按钮 */
.mobile-menu-toggle {
  display: none;
  background: none;
  border: 1px solid var(--jd-gray-light);
  border-radius: 8px;
  padding: 8px;
  color: var(--jd-black);
  cursor: pointer;
  transition: all 0.3s ease;
}

.mobile-menu-toggle:hover {
  background-color: var(--jd-gray-light);
  border-color: var(--jd-red);
  color: var(--jd-red);
  transform: translateY(-1px);
}

/* 分类菜单 */
.category-dropdown {
  position: relative;
}

.category-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background-color: var(--jd-red);
  color: white;
  border: none;
  border-radius: 25px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  white-space: nowrap;
}

.category-button:hover {
  background: linear-gradient(135deg, #c81623, #ff7875);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(225, 37, 27, 0.4);
}

.category-menu {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 8px;
  background-color: var(--jd-white);
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.18);
  width: 200px;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s ease;
  z-index: 101;
  border: 1px solid var(--jd-gray-light);
}

.category-menu.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.category-menu:before {
  content: '';
  position: absolute;
  top: -8px;
  left: 20px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 8px solid var(--jd-white);
}

.category-items {
  padding: 8px 0;
}

.category-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  color: var(--jd-black);
  text-decoration: none;
  font-size: 14px;
  transition: all 0.3s ease;
  border-radius: 6px;
  margin: 2px 10px;
  position: relative;
  overflow: hidden;
}

.category-item:hover {
  background-color: rgba(225, 37, 27, 0.08);
  color: var(--jd-red);
  transform: translateX(4px);
}

.category-item:before {
  content: '';
  position: absolute;
  left: -100%;
  top: 50%;
  width: 100%;
  height: 2px;
  background-color: var(--jd-red);
  transform: translateY(-50%);
  transition: all 0.3s ease;
}

.category-item:hover:before {
  left: 100%;
}

.category-more {
  color: var(--jd-gray);
}

.category-item:hover .category-more {
  color: var(--jd-red);
}

/* 导航链接 */
.nav-links {
  display: flex;
  gap: 16px;
  margin-left: 20px;
  align-items: center;
}

.nav-link {
  color: var(--jd-black);
  text-decoration: none;
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.3s ease;
  position: relative;
  white-space: nowrap;
}

.nav-link:hover {
  color: var(--jd-red);
  background-color: rgba(225, 37, 27, 0.05);
  transform: translateY(-1px);
}

.nav-link.active {
  color: var(--jd-red);
  font-weight: 600;
  background-color: rgba(225, 37, 27, 0.08);
}

.nav-link:after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 0;
  height: 2px;
  background-color: var(--jd-red);
  transition: all 0.3s ease;
  transform: translateX(-50%);
}

.nav-link:hover:after {
  width: 80%;
}

/* 登录按钮 */
.login-section {
  display: flex;
  align-items: center;
}

.login-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: linear-gradient(135deg, var(--jd-red), #ff4d4f);
  border: none;
  color: var(--jd-white);
  border-radius: 25px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(225, 37, 27, 0.25);
  min-width: 100px;
  justify-content: center;
}

.login-button:hover {
  color: var(--jd-red);
  border-color: var(--jd-red);
  background-color: rgba(225, 37, 27, 0.05);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

/* 用户菜单 */
.user-menu {
  position: relative;
}

.user-menu-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: none;
  border: 1px solid var(--jd-gray-light);
  border-radius: 25px;
  cursor: pointer;
  font-size: 14px;
  color: var(--jd-black);
  transition: all 0.3s ease;
  position: relative;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.user-menu-button:hover {
  color: var(--jd-red);
  border-color: var(--jd-red);
  background-color: rgba(225, 37, 27, 0.05);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.user-name {
  font-size: 14px;
}

.user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--jd-white);
  border: 1px solid var(--jd-gray-light);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  padding: 8px 0;
  min-width: 190px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all 0.3s ease;
  z-index: 1000;
  backdrop-filter: blur(8px);
  background-color: rgba(255, 255, 255, 0.95);
}

.user-dropdown.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.user-dropdown:before {
  content: '';
  position: absolute;
  top: -8px;
  right: 20px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 8px solid var(--jd-white);
}

.user-dropdown .dropdown-item {
  display: block;
  width: 100%;
  padding: 12px 24px;
  background: none;
  border: none;
  color: var(--jd-black);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: all 0.3s ease;
  text-decoration: none;
  border-radius: 6px;
  margin: 2px 10px;
  position: relative;
  overflow: hidden;
}

.user-dropdown .dropdown-item:hover {
  background-color: rgba(225, 37, 27, 0.08);
  color: var(--jd-red);
  transform: translateX(4px);
}

.user-dropdown .dropdown-item:before {
  content: '';
  position: absolute;
  left: -100%;
  top: 50%;
  width: 100%;
  height: 2px;
  background-color: var(--jd-red);
  transform: translateY(-50%);
  transition: all 0.3s ease;
}

.user-dropdown .dropdown-item:hover:before {
  left: 100%;
}

.dropdown-divider {
  height: 1px;
  background-color: var(--jd-gray-light);
  margin: 5px 0;
}

.dropdown-item.logout {
  color: var(--jd-gray);
}

.dropdown-item.logout:hover {
  color: var(--jd-red);
}

/* 购物车 */
.cart-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  background: none;
  color: var(--jd-black);
  border: 1px solid var(--jd-gray-light);
  border-radius: 20px;
  text-decoration: none;
  transition: all 0.3s ease;
  position: relative;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  min-width: 100px;
  justify-content: center;
  flex-shrink: 0;
}

.cart-button:hover {
  color: var(--jd-red);
  border-color: var(--jd-red);
  background-color: rgba(225, 37, 27, 0.05);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.cart-count {
  position: absolute;
  top: -8px;
  right: -8px;
  background: linear-gradient(135deg, var(--jd-red), #ff4d4f);
  color: var(--jd-white);
  font-size: 12px;
  font-weight: bold;
  padding: 2px 8px;
  border-radius: 12px;
  min-width: 20px;
  text-align: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* 移动端菜单 */
.mobile-menu {
  position: fixed;
  top: 0;
  left: -300px;
  width: 300px;
  height: 100vh;
  background: var(--jd-white);
  box-shadow: var(--jd-shadow-lg);
  z-index: 2000;
  transition: all 0.3s ease;
  overflow-y: auto;
}

.mobile-menu.show {
  left: 0;
}

.mobile-nav {
  padding: 60px 20px 20px;
}

.mobile-category, .mobile-user {
  margin-bottom: 30px;
}

.mobile-category h3, .mobile-user h3 {
  font-size: 16px;
  font-weight: bold;
  color: var(--jd-black);
  margin-bottom: 15px;
  border-bottom: 2px solid var(--jd-red);
  padding-bottom: 8px;
  position: relative;
}

.mobile-category h3:after, .mobile-user h3:after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 40px;
  height: 2px;
  background-color: var(--jd-red);
}

.mobile-category-list, .mobile-user-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.mobile-category-link, .mobile-user-link {
  display: block;
  padding: 12px 0;
  color: var(--jd-black);
  text-decoration: none;
  font-size: 14px;
  border-bottom: 1px solid var(--jd-gray-light);
  transition: all 0.3s ease;
  position: relative;
  padding-left: 16px;
}

.mobile-category-link:before, .mobile-user-link:before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  width: 6px;
  height: 6px;
  background-color: var(--jd-gray-light);
  border-radius: 50%;
  transform: translateY(-50%);
  transition: all 0.3s ease;
}

.mobile-category-link:hover, .mobile-user-link:hover {
  color: var(--jd-red);
  padding-left: 24px;
  background-color: rgba(225, 37, 27, 0.05);
}

.mobile-category-link:hover:before, .mobile-user-link:hover:before {
  background-color: var(--jd-red);
  transform: translateY(-50%) scale(1.3);
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .header-content {
    gap: 15px;
  }
  
  .logo-section {
    width: 150px;
  }
  
  .jd-logo {
    width: 150px;
    height: 50px;
  }
  
  .nav-links {
    gap: 15px;
  }
  
  .nav-link {
    font-size: 14px;
  }
}

@media (max-width: 1024px) {
  .nav-links {
    display: none;
  }
  
  .mobile-menu-toggle {
    display: block;
  }
  
  .category-dropdown {
    display: none;
  }
}

@media (max-width: 768px) {
  .top-bar {
    display: none;
  }
  
  .header-content {
    padding: 10px 16px;
    gap: 10px;
  }
  
  .logo-section {
    width: 120px;
  }
  
  .jd-logo {
    width: 120px;
    height: 40px;
  }
  
  .search-input {
    font-size: 12px;
    padding: 8px 12px;
  }
  
  .search-button {
    padding: 8px 15px;
    font-size: 12px;
  }
  
  .user-actions {
    gap: 10px;
  }
  
  .login-button, .cart-button {
    padding: 6px 12px;
    font-size: 12px;
  }
  
  .login-button span, .user-name, .cart-button span {
    display: none;
  }
}

@media (max-width: 480px) {
  .header-content {
    padding: 8px 12px;
    gap: 8px;
  }
  
  .logo-section {
    width: 100px;
  }
  
  .jd-logo {
    width: 100px;
    height: 35px;
  }
  
  .search-input {
    font-size: 11px;
  }
  
  .search-button {
    padding: 8px 12px;
    font-size: 11px;
  }
}

/* 显示/隐藏辅助类 */
.hidden-desktop {
  display: none !important;
}

.hidden-mobile {
  display: flex;
}

@media (max-width: 1024px) {
  .hidden-desktop {
    display: block !important;
  }
  
  .hidden-mobile {
    display: none !important;
  }
}

/* 样式部分添加用户头像样式 */
.user-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  margin-right: 8px;
  background-color: var(--jd-gray-light);
}

/* 其余样式保持不变 */
</style>